package com.sikaryofficial.backend.service.impl;

import cn.hutool.core.text.CharSequenceUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sikaryofficial.backend.domain.entity.ArticleExt;
import com.sikaryofficial.backend.domain.vo.infomation.ArticleExtVO;
import com.sikaryofficial.backend.mapper.ArticleExtMapper;
import com.sikaryofficial.backend.service.IArticleExtService;
import com.sikaryofficial.system.api.model.infomation.ArticleCategoryObjVO;
import com.sikaryofficial.system.api.model.infomation.FriendObjVO;
import com.sikaryofficial.system.api.model.infomation.TopicObjVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 文章扩展Service业务层处理
 *
 * @author qinjinyuan
 * @date 2024-04-15
 */
@Service
public class ArticleExtServiceImpl extends ServiceImpl<ArticleExtMapper, ArticleExt> implements IArticleExtService {
    @Autowired
    private ArticleExtMapper articleExtMapper;

    @Override
    public ArticleExt getVOById(Long articleId) {
        ArticleExtVO articleExtVO = articleExtMapper.getVOById(articleId);
        if (Objects.isNull(articleExtVO)) {
            return null;
        }
        ArticleExt articleExt = new ArticleExt();
        articleExt.setArticleId(articleId);
        if (CharSequenceUtil.isNotBlank(articleExtVO.getArticleCategoryList() )) {
            articleExt.setArticleCategoryList(JSON.parseArray(articleExtVO.getArticleCategoryList(), ArticleCategoryObjVO.class));
        }
        if (CharSequenceUtil.isNotBlank(articleExtVO.getTopicList() )) {
            articleExt.setTopicList(JSON.parseArray(articleExtVO.getTopicList(), TopicObjVO.class));
        }
        if (CharSequenceUtil.isNotBlank(articleExtVO.getFriendList() )) {
            articleExt.setFriendList(JSON.parseArray(articleExtVO.getFriendList(), FriendObjVO.class));
        }
        return articleExt;
    }

    @Override
    public List<ArticleExtVO> getDataByIds(List<Long> articleIds) {
        return articleExtMapper.getDataByIds(articleIds);
    }
}
